package activemq_chap7;

import java.io.File;
import java.net.URI;

import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.store.kahadb.KahaDBStore;

public class DemoBrokerFactory {

	public static void main(String[] args) {
		System.setProperty("activemq.base", System.getProperty("user.dir"));
		try {
			URI brokerURI = new URI("xbean:target/classes/activemq.xml");
			BrokerService brokerService =  BrokerFactory.createBroker(brokerURI);
			brokerService.setBrokerName("factoryBroker");
			brokerService.setDataDirectory("data/");
			File dataFileDir = new File("data/factoryBroker/kahadb");
			KahaDBStore kahaDBStore = new KahaDBStore();
			kahaDBStore.setDirectory(dataFileDir);
			kahaDBStore.setJournalMaxFileLength(1024*100);
			kahaDBStore.setIndexWriteBatchSize(100);
			// do the index write in a separate thread
			kahaDBStore.setEnableIndexWriteAsync(true);
			brokerService.setPersistenceAdapter(kahaDBStore);
			brokerService.start();
			System.out.println("Start success !");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
